// evalaute.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
     stars: [0, 1, 2, 3, 4],
     normalSrc: '../../image/normal.png',
     selectedSrc: '../../image/selected.png',
     halfSrc: '../../image/half.png',
     key: 0,//评分
     num: 0,
  },
  /**
 * 生命周期函数--监听页面加载
 */
  onLoad: function (options) {
    this.setData({
      ordercode: options.ordercode,
      starttime: options.starttime,
      price: options.price,
      startdate: options.startdate,
      startplace: options.startplace,
      endplace: options.endplace,
      orderstatus: options.orderstatus,
    })
  },
  nonono: function () {
    wx.showModal({
      content: '评价字数不能超过50个字哦！',
      showCancel: false,
      success: function (res) {
        if (res.confirm) {
          console.log('确定')
        }
      }
    });
  },
  content:function(e){
    this.setData({
      num: e.detail.value.length,
      content: e.detail.value
    })
    if (e.detail.value.length == 50){
      this.nonono();
      return
    }
  },

  selectLeft: function (e) {
    var key = e.currentTarget.dataset.key
    if (this.data.key == 0.5 && e.currentTarget.dataset.key == 0.5) {
      //只有一颗星的时候,再次点击,变为0颗
      key = 0;
    }
    this.setData({
      key: key
    })
  },
  //点击左边,整颗星
  selectRight: function (e) {
    var key = e.currentTarget.dataset.key
    this.setData({
      key: key
    })
  },


  // 为检票评价提示框
  Alert: function () {
    wx.showModal({
      content: '请您检票之后再来做评价哦！',
      showCancel: false,
      success: function (res) {
        if (res.confirm) {
          console.log('确定')
        }
      }
    });
  },
  // 评分
  score: function () {
    wx.showModal({
      content: '您要评几分呢？',
      showCancel: false,
      success: function (res) {
        if (res.confirm) {
          console.log('确定')
        }
      }
    });
  },

  mark:function(){
    var that = this;
    if(this.data.key > 0){
      wx.request({
        url: app.serviceurl + 'CarRental/CarRentalComment',
        header: {
          Authorization: "Bearer " + app.accesstoken
        },
        data: { OrderCode: this.data.ordercode, CommentSorce: that.data.key, CommentContent: this.data.content },
        dataType: 'json',
        success: function (res) {
          if (res.data.Result == false){
            that.Alert();
          }else{
            wx.navigateBack({});
          }
        },
        fail: function (err) {
          console.log(err)
        }
      })
    }
    else{
      this.score();
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
  if (res.from === 'menu') {
      return app.OnShare();
    }
  }
})